<template>
  <div class="app-container">
    <div class="spaceline" />
    <el-divider content-position="left">配置项</el-divider>
    <el-form
      ref="form"
      v-loading="infoLoading"
      class="common-form"
      :model="form"
      label-width="170px"
      :inline-message="true"
    >
      <el-form-item label="快速招聘联系方式">
        <el-radio-group v-model="form.fast_job_contact">
          <el-radio :label="0">不限</el-radio>
          <el-radio :label="1">登录后查看</el-radio>
        </el-radio-group>
      </el-form-item>
	  
	  <el-form-item label="快速招聘发布次数" >
        <el-input v-model.number="form.fast_job_num" style="width:200px;margin-right:15px;" class="small" >
          <template slot="append">条/天</template>
        </el-input>
        <el-tooltip
			class="item"
			effect="dark"
			content="0为不允许发布"
			placement="top-start"
		  >
			<i class="el-icon-info" />
		</el-tooltip>
      </el-form-item>
      <el-form-item label="快速求职联系方式">
        <el-radio-group v-model="form.fast_resume_contact">
          <el-radio :label="0">不限</el-radio>
          <el-radio :label="1">登录后查看</el-radio>
        </el-radio-group>
      </el-form-item>
	  <el-form-item label="快速求职发布次数" >
        <el-input v-model.number="form.fast_resume_num" style="width:200px;margin-right:15px;" class="small" >
          <template slot="append">条/天</template>
        </el-input>
        <el-tooltip
			class="item"
			effect="dark"
			content="0为不允许发布"
			placement="top-start"
		  >
			<i class="el-icon-info" />
		</el-tooltip>
      </el-form-item>
	  
      <el-form-item label="">
        <el-button type="primary" @click="onSubmit('form', 1)">保存</el-button>
      </el-form-item>
      <el-divider content-position="left">审核设置</el-divider>
      <el-form-item label="新发布简历">
        <el-radio-group v-model="form.fast_resume_add_audit">
          <el-radio :label="0">未审核</el-radio>
          <el-radio :label="1">已审核</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="修改后简历">
        <el-radio-group v-model="form.fast_resume_edit_audit">
          <el-radio :label="-1">保持不变</el-radio>
          <el-radio :label="0">未审核</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="新发布职位">
        <el-radio-group v-model="form.fast_job_add_audit">
          <el-radio :label="0">未审核</el-radio>
          <el-radio :label="1">已审核</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="修改后职位">
        <el-radio-group v-model="form.fast_job_edit_audit">
          <el-radio :label="-1">保持不变</el-radio>
          <el-radio :label="0">未审核</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="">
        <el-button type="primary" @click="onSubmit('form')">保存</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { setConfig } from '@/api/configuration'
import apiArr from '@/api'
import { getToken } from '@/utils/auth'

export default {
  data() {
    return {
      form: {
        fast_job_contact: '',
        fast_resume_contact: '',
        fast_job_num: 0,
        fast_resume_num: 0,
        fast_resume_add_audit: 0,
        fast_job_add_audit: 0,
        fast_resume_edit_audit: 0,
        fast_job_edit_audit: 0
      }
    }
  },
  created() {
    this.fetchInfo()
  },
  methods: {
    fetchInfo() {
      this.infoLoading = true
      const param = {}
      setConfig(param, 'get')
        .then(response => {
          const {
            fast_job_contact, fast_resume_contact, fast_job_num, fast_resume_num, fast_resume_add_audit,
            fast_job_add_audit, fast_resume_edit_audit, fast_job_edit_audit
          } = {
            ...response.data
          }
          this.form = {
            fast_job_contact,
            fast_resume_contact, fast_job_num, fast_resume_num,
            fast_job_add_audit,  fast_job_edit_audit, fast_resume_edit_audit,
            fast_resume_add_audit
          }
          this.form.fast_job_contact = parseInt(fast_job_contact)
          this.form.fast_resume_contact = parseInt(fast_resume_contact)
          this.form.fast_job_num = parseInt(fast_job_num)
          this.form.fast_resume_num = parseInt(fast_resume_num)
          this.form.fast_job_add_audit = parseInt(fast_job_add_audit)
          this.form.fast_job_edit_audit = parseInt(fast_job_edit_audit)
          this.form.fast_resume_add_audit = parseInt(fast_resume_add_audit)
          this.form.fast_resume_edit_audit = parseInt(fast_resume_edit_audit)
          this.infoLoading = false
        })
        .catch(() => {
        })
    },
    onSubmit(formName, top) {
      let insertData = { ...this.form }
      if (top) {
        delete insertData.fast_job_add_audit
        delete insertData.fast_job_edit_audit
        delete insertData.fast_resume_add_audit
        delete insertData.fast_resume_edit_audit
      } else {
        insertData = {
          fast_job_add_audit: insertData.fast_job_add_audit,
          fast_job_edit_audit: insertData.fast_job_edit_audit,
          fast_resume_add_audit: insertData.fast_resume_add_audit,
          fast_resume_edit_audit: insertData.fast_resume_edit_audit
        }
      }
      this.$refs[formName].validate(valid => {
        if (valid) {
          setConfig(insertData)
            .then(response => {
              this.$store.dispatch('config/getConfigInfo')
              this.$message.success(response.message)
              return true
            })
            .catch(() => {
            })
        } else {
          return false
        }
      })
    }
  }
}
</script>
<style scoped>
.el-divider {
  background: none;
}

.squarelogo-uploader {
  display: inline-block;
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  width: 102px;
  height: 102px;
}

.squarelogo-uploader img {
  width: 100px;
  height: 100px;
  border-radius: 6px;
}

.squarelogo-uploader:hover {
  border-color: #409eff;
}

.squarelogo-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 100px;
  height: 100px;
  line-height: 100px;
  text-align: center;
}
</style>
